const Router = require("@koa/router");
const userRouter = new Router({ prefix: "/user" });

// 创建用户的中间件
const {
	create,
	getAvatarInfo,
	list,
	update
} = require("../controller/user.controller");

// 校验用户名和密码的中间件
const { verifyUser, handlePassword } = require("../middleware/user.middleware");
const { verifyAuth } = require("../middleware/auth.middleware");
const userRequest = require("../request/user.request");

// 注册
userRouter.post("/", userRequest, verifyUser, handlePassword, create);
// 列表
userRouter.get("/", verifyAuth, list);
// 修改
userRouter.patch(
	"/",
	verifyAuth,
	userRequest,
	verifyUser,
	handlePassword,
	update
);
// 获取用户头像
userRouter.get("/avatar/:userId", getAvatarInfo);

module.exports = userRouter;
